
class HttpException extends Error{  //定义一个已知错误的基类
   constructor(msg="服务器异常", errorCode=10000, code) {
       super();
       this.errorCode = errorCode;
       this.code = code;
       this.msg = msg;
   }
}

// 参数错误出现的异常
class ParameterException extends HttpException{
    constructor(msg, errorCode) {
      super();  
      this.code = 400;
      this.msg = msg || '参数错误';
      this.errorCode = errorCode || 10000;
    }
}

// 成功返回的状态
class Success extends HttpException{
    constructor(msg, errorCode) {
        super();
        this.code = 201;
        this.msg = msg || 'ok';
        this.errorCode = errorCode || 0;
    }
}

// 资源找不到抛出的异常
class NotFound extends HttpException{
    constructor(msg, errorCode) {
        super();
        this.code = 404;
        this.msg = msg || '资源未找到';
        this.errorCode = errorCode || 10000
    }
}

// 授权失败抛出的异常
class AuthFailed extends HttpException{
    constructor(msg, errorCode) {
        super();
        this.code = 401;
        this.msg = msg || '授权失败';
        this.errorCode = errorCode || 10004
    }
}

// 禁止访问抛出的异常
class Forbbiden extends HttpException {
    constructor(msg, errorCode){
        super();
        this.code = 403;
        this.msg = msg || '禁止访问';
        this.errorCode = errorCode || 10006
    }
}

// 点赞出现的异常
class LikeError extends HttpException{
    constructor(msg, errorCode) {
        super();
        this.code = 400;
        this.msg = msg || '您已经点赞过';
        this.errorCode = errorCode || 60001;
    }
}

//取消点赞出现的异常
class DislikeError extends HttpException{
    constructor(msg, errorCode){
        super();
        this.code = 400;
        this.msg = msg || '您已取消点赞';
        this.errorCode = errorCode || 60002;
    }
}


module.exports = {
    HttpException,
    ParameterException,
    Success,
    NotFound,
    AuthFailed,
    Forbbiden,
    LikeError,
    DislikeError
}